package com.rui.cn.provider.controller.system;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.plugins.pagination.Pagination;
import com.rui.cn.entity.system.SysRole;
import com.rui.cn.provider.service.system.SysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/sysrole")
public class SysRoleController {
    @Autowired
    private SysRoleService sysRoleService;
    
    @GetMapping(value = "/getRoleList/{id}")
    public List<SysRole> getRoleList(@PathVariable("id")Integer id){
        return  sysRoleService.getRoleList(id);
    }

    @PostMapping(value = "/roleList")
    public Page<SysRole> roleList(@RequestBody Page pagination, @RequestParam(name = "search",required = false) String search, @RequestParam(required = false,name = "sortBy") String sortBy, @RequestParam(required = false,name = "order") String order){
        return sysRoleService.roleList(pagination,search,sortBy,order);
    }

    @GetMapping(value = "/selectUserRole/{id}")
    public List<SysRole> selectUserRole(@PathVariable("id") Integer id){
        return sysRoleService.selectUserRole(id);
    }

    @GetMapping(value = "/selectList")
    public List<SysRole> selectList(){
        return sysRoleService.selectList(new Wrapper<SysRole>() {
            @Override
            public String getSqlSegment() {
                return null;
            }
        });
    }

    @PutMapping(value = "/updateById")
    public boolean updateById(@RequestBody SysRole role){
        return  sysRoleService.updateById(role);
    }

    @PostMapping(value = "/insert")
    public boolean insert(@RequestBody SysRole role){
        return sysRoleService.insert(role);
    }

    @GetMapping(value = "/selectById/{id}")
    public SysRole selectById(@PathVariable("id") Integer id){
        return sysRoleService.selectById(id);
    }

    @DeleteMapping(value = "/deleteBatchIds")
    public boolean deleteBatchIds(@RequestBody List<Integer> integers){
        return sysRoleService.deleteBatchIds(integers);
    }
}
